import { FakeApi } from '@wowon/utils';
import { getCurrentUser } from '../../auth-center';

// style = {
//   mode: '',
//   status: '',
//   color: '',
//   size: '',
//   round: '',
//   animation: ''
// }

// ------------------------ 数据 -----------------------------
const initData = [
  {
    id: '100',
    pid: '_root',
    rootid: '_root',
    label: '通用状态',
    value: 'CommonStatus',
    description: '系统通用状态',
    style: null,
    sort: 0,
  },
  {
    id: '1000',
    pid: '100',
    rootid: '100',
    label: '禁用',
    value: '0',
    description: '',
    style: '{"mode":"tag","status":"error","round":0,"animation":0}',
    sort: 0,
  },
  {
    id: '1001',
    pid: '100',
    rootid: '100',
    label: '启用',
    value: '1',
    description: '',
    style: '{"mode":"tag","status":"success","round":0,"animation":1}',
    sort: 1,
  },
  {
    id: '200',
    pid: '_root',
    rootid: '_root',
    label: '*系统可选主题',
    value: 'SYSTEM_OPTIONS_THEME',
    description: '系统支持的主题选项',
    style: null,
    sort: 0,
  },
  {
    id: '2000',
    pid: '200',
    rootid: '200',
    label: '默认浅色',
    value: 'default-light',
    description: '默认主题',
    style: '{"preview":"/wowon/theme/default-light/preview.png"}',
    sort: 0,
  },
  {
    id: '2001',
    pid: '200',
    rootid: '200',
    label: '默认深色',
    value: 'default-dark',
    description: '暗色',
    style: '{"preview":"/wowon/theme/default-dark/preview.png"}',
    sort: 1,
  },
  {
    id: '300',
    pid: '_root',
    rootid: '_root',
    label: '*系统可选语言',
    value: 'SYSTEM_OPTIONS_LANGUAGE',
    description: '系统支持的语言选项',
    style: null,
    sort: 0,
  },
  {
    id: '3000',
    pid: '300',
    rootid: '300',
    label: '中文',
    value: 'chinese_simplified',
    description: '默认语言',
    style: null,
    sort: 0,
  },
  {
    id: '400',
    pid: '_root',
    rootid: '_root',
    label: '*系统页面',
    value: 'SYSTEM_OPTIONS_COMPONENT',
    description: '系统页面组件路径',
    style: null,
    sort: 0,
  },
  {
    id: '4000',
    pid: '400',
    rootid: '400',
    label: '首页',
    value: './dashboard/home',
    description: '',
    style: null,
    sort: 0,
  },
  {
    id: '4001',
    pid: '400',
    rootid: '400',
    label: '工作台',
    value: './dashboard/workplace',
    description: '',
    style: null,
    sort: 0,
  },
  {
    id: '4002',
    pid: '400',
    rootid: '400',
    label: '统计分析',
    value: './dashboard/analysis',
    description: '',
    style: null,
    sort: 0,
  },
  {
    id: '4003',
    pid: '400',
    rootid: '400',
    label: '用户管理',
    value: './access/user',
    description: '',
    style: null,
    sort: 0,
  },
  {
    id: '4004',
    pid: '400',
    rootid: '400',
    label: '角色管理',
    value: './access/role',
    description: '',
    style: null,
    sort: 0,
  },
  {
    id: '4005',
    pid: '400',
    rootid: '400',
    label: '菜单管理',
    value: './access/menu',
    description: '',
    style: null,
    sort: 0,
  },
  {
    id: '500',
    pid: '_root',
    rootid: '_root',
    label: '平台',
    value: 'PlatformList',
    description: '系统平台列表',
    style: null,
    sort: 0,
  },
  {
    id: '5000',
    pid: '500',
    rootid: '500',
    label: '安卓',
    value: 'android',
    description: '',
    style: '{"mode":"text","icon":"AndroidOutlined","color":"#42a15a"}',
    sort: 0,
  },
  {
    id: '5001',
    pid: '500',
    rootid: '500',
    label: '苹果',
    value: 'apple',
    description: '',
    style: '{"mode":"text","icon":"AppleOutlined","color":"#595959"}',
    sort: 0,
  },
  {
    id: '5002',
    pid: '500',
    rootid: '500',
    label: '浏览器',
    value: 'web',
    description: '',
    style: '{"mode":"text","icon":"ChromeOutlined","color":"#2196f3"}',
    sort: 0,
  },
  {
    id: '5003',
    pid: '500',
    rootid: '500',
    label: 'H5',
    value: 'h5',
    description: '',
    style: '{"mode":"text","icon":"Html5Outlined","color":"#f44336"}',
    sort: 0,
  },
  {
    id: '5004',
    pid: '500',
    rootid: '500',
    label: '微信公众号',
    value: 'wechat_h5',
    description: '',
    style: '{"mode":"text","icon":"WechatOutlined","color":"#43ad3f"}',
    sort: 0,
  },
  {
    id: '5005',
    pid: '500',
    rootid: '500',
    label: '微信小程序',
    value: 'wechat',
    description: '',
    style: '{"mode":"text","icon":"WechatOutlined","color":"#43ad3f"}',
    sort: 0,
  },
  {
    id: '5006',
    pid: '500',
    rootid: '500',
    label: '支付宝小程序',
    value: 'alipay',
    description: '',
    style: '{"mode":"text","icon":"AlipayOutlined","color":"#3f51b5"}',
    sort: 0,
  },
  {
    id: '5007',
    pid: '500',
    rootid: '500',
    label: '鸿蒙',
    value: 'harmony',
    description: '',
    style: '{"mode":"text","icon":"HarmonyOSOutlined","color":"#673ab7"}',
    sort: 0,
  },
];
// ------------------------ 数据 -----------------------------

// ------------------------ 操作逻辑 -----------------------------
export const dictList = new FakeApi(initData, {
  queryType: {
    rootid: 'is',
    label: 'like',
    value: 'like',
  },
  sort: (x, y) => {
    let num = x.sort - y.sort;
    if (num !== 0) return num;
    num = new Date(y.updateTime) - new Date(x.updateTime);
    if (num !== 0) return num;
  },
});

export default {
  'GET /mock/dict/query': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await dictList.query(req.query);
    res.json(result);
  },
  'POST /mock/dict/create': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await dictList.create(req.body);
    res.json(result);
  },
  'POST /mock/dict/update': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await dictList.update(req.body);
    res.json(result);
  },
  'POST /mock/dict/remove': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await dictList.remove(req.body);
    res.json(result);
  },
};
// ------------------------ 操作逻辑 -----------------------------
